﻿using System;
using FotoAlbum.Sort;

namespace FotoAlbum
{
    partial class FormJ
    {
        private void Sort()
        {
            _items.Sort();

            if (FICompare.Order == SortOrder.Descending)
                _items.Reverse();
        }

        #region SortType
        private void SetSort_Name(object sender, EventArgs e)
        {
            TurnChecks(SortType.Name);
        }

        private void SetSort_FileSize(object sender, EventArgs e)
        {
            TurnChecks(SortType.Filesize);
        }

        private void SetSort_DateOfCreation(object sender, EventArgs e)
        {
            TurnChecks(SortType.DateOfCreation);
        }

        private void TurnChecks(SortType type)
        {
            FICompare.Type = type;
            SortName.Checked = (type == SortType.Name);
            SortFileSize.Checked = (type == SortType.Filesize);
            SortDateOfCreation.Checked = (type == SortType.DateOfCreation);
            DisplayItems();
        }
        #endregion

        #region SortOrder
        private void SetSort_Ascending(object sender, EventArgs e)
        {
            TurnChecks(SortOrder.Ascending);
        }

        private void SetSort_Descending(object sender, EventArgs e)
        {
            TurnChecks(SortOrder.Descending);
        }

        private void TurnChecks(SortOrder order)
        {
            FICompare.Order = order;
            SortAscending.Checked = (order == SortOrder.Ascending);
            SortDescending.Checked = (order == SortOrder.Descending);
            DisplayItems();
        }
        #endregion
    }
}
